﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Hermes.Web.Address
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int ID=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(ID);
				}
			}
		}
			
	private void ShowInfo(int ID)
	{
		Hermes.BLL.Address bll=new Hermes.BLL.Address();
		Hermes.Model.Address model=bll.GetModel(ID);
		this.lblID.Text=model.ID.ToString();
		this.txtContact.Text=model.Contact;
		this.txtCompany.Text=model.Company;
		this.txtStreet.Text=model.Street;
		this.txtDistrict.Text=model.District;
		this.txtCity.Text=model.City;
		this.txtProvince.Text=model.Province;
		this.txtPostcode.Text=model.Postcode;
		this.txtCountry.Text=model.Country;
		this.txtEmail.Text=model.Email;
		this.txtMobile.Text=model.Mobile;
		this.txtPhone.Text=model.Phone;
		this.txtLastUpdate.Text=model.LastUpdate.ToString();
		this.txtType.Text=model.Type.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtContact.Text.Trim().Length==0)
			{
				strErr+="Contact不能为空！\\n";	
			}
			if(this.txtCompany.Text.Trim().Length==0)
			{
				strErr+="Company不能为空！\\n";	
			}
			if(this.txtStreet.Text.Trim().Length==0)
			{
				strErr+="Street不能为空！\\n";	
			}
			if(this.txtDistrict.Text.Trim().Length==0)
			{
				strErr+="District不能为空！\\n";	
			}
			if(this.txtCity.Text.Trim().Length==0)
			{
				strErr+="City不能为空！\\n";	
			}
			if(this.txtProvince.Text.Trim().Length==0)
			{
				strErr+="Province不能为空！\\n";	
			}
			if(this.txtPostcode.Text.Trim().Length==0)
			{
				strErr+="Postcode不能为空！\\n";	
			}
			if(this.txtCountry.Text.Trim().Length==0)
			{
				strErr+="Country不能为空！\\n";	
			}
			if(this.txtEmail.Text.Trim().Length==0)
			{
				strErr+="Email不能为空！\\n";	
			}
			if(this.txtMobile.Text.Trim().Length==0)
			{
				strErr+="Mobile不能为空！\\n";	
			}
			if(this.txtPhone.Text.Trim().Length==0)
			{
				strErr+="Phone不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtLastUpdate.Text))
			{
				strErr+="LastUpdate格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtType.Text))
			{
				strErr+="Type格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int ID=int.Parse(this.lblID.Text);
			string Contact=this.txtContact.Text;
			string Company=this.txtCompany.Text;
			string Street=this.txtStreet.Text;
			string District=this.txtDistrict.Text;
			string City=this.txtCity.Text;
			string Province=this.txtProvince.Text;
			string Postcode=this.txtPostcode.Text;
			string Country=this.txtCountry.Text;
			string Email=this.txtEmail.Text;
			string Mobile=this.txtMobile.Text;
			string Phone=this.txtPhone.Text;
			DateTime LastUpdate=DateTime.Parse(this.txtLastUpdate.Text);
			int Type=int.Parse(this.txtType.Text);


			Hermes.Model.Address model=new Hermes.Model.Address();
			model.ID=ID;
			model.Contact=Contact;
			model.Company=Company;
			model.Street=Street;
			model.District=District;
			model.City=City;
			model.Province=Province;
			model.Postcode=Postcode;
			model.Country=Country;
			model.Email=Email;
			model.Mobile=Mobile;
			model.Phone=Phone;
			model.LastUpdate=LastUpdate;
			model.Type=Type;

			Hermes.BLL.Address bll=new Hermes.BLL.Address();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
